using System;
using ACS.Compiler.Tables;
using ACS.Compiler.Tables.Modes;
using ACS.Compiler.Util;

namespace ACS.Compiler.Tree.Impl
{
    public class Arrow : Operator
    {
        public override string OperatorToString()
        {
            return "";
        }

        public override Operators OperatorType
        {
            get { return Operators.Arrow; }
        }

        public override Mode Mode
        {
            get
            {
                return BoolMode.Instance;
            }
        }

        public override string ToDeclareString()
        {
            string s1 = Left.ToDeclareString();
            string s2 = Right.ToDeclareString();
            return String.Format("!(({0})||({2}))", s1, OperatorToString(), s2);
        }

        public override void Resolve(string ns, DataTable localData)
        {
            Mode leftMode = Left.ModeResolveExpression(ns, localData, null);
            Mode rigthMode = Right.ModeResolveExpression(ns, localData, null);
            if (!ModesTable.Castable(leftMode, rigthMode))
            {
                Logger.Instance.TraceModesNotEquals(leftMode, rigthMode, this);
            }
            if (! ModesTable.Castable(leftMode, BoolMode.Instance)  )
            {
                Logger.Instance.TraceWrongMode(leftMode, this);
            }
            _mode = leftMode;
        }
    }
}